import request from '@/utils/request'

// 房源相关接口
export function searchHouses(params) {
  return request({
    url: '/api/rental/houses/search',
    method: 'get',
    params
  })
}

export function getHouseById(id) {
  return request({
    url: `/api/rental/houses/${id}`,
    method: 'get'
  })
}

export function getRecommendedHouses(userId, limit = 5) {
  return request({
    url: '/api/rental/houses/recommended',
    method: 'get',
    params: { userId, limit }
  })
}

export function getSimilarHouses(houseId, limit = 5) {
  return request({
    url: `/api/rental/houses/${houseId}/similar`,
    method: 'get',
    params: { limit }
  })
}

// 订单相关接口
export function createRentalOrder(data) {
  return request({
    url: '/api/rental/orders',
    method: 'post',
    data
  })
}

export function getRentalOrder(orderNo) {
  return request({
    url: `/api/rental/orders/${orderNo}`,
    method: 'get'
  })
}

export function getUserRentalOrders(userId, params) {
  return request({
    url: `/api/rental/orders/user/${userId}`,
    method: 'get',
    params
  })
}

export function cancelRentalOrder(orderNo) {
  return request({
    url: `/api/rental/orders/${orderNo}/cancel`,
    method: 'post'
  })
}

export function confirmRentalOrder(orderNo) {
  return request({
    url: `/api/rental/orders/${orderNo}/confirm`,
    method: 'post'
  })
}

// 价格计算接口
export function calculateRent(houseId, userCreditScore) {
  return request({
    url: `/api/rental/houses/${houseId}/rent`,
    method: 'get',
    params: { userCreditScore }
  })
}

export function calculateDeposit(houseId, userCreditScore) {
  return request({
    url: `/api/rental/houses/${houseId}/deposit`,
    method: 'get',
    params: { userCreditScore }
  })
}

export function checkDepositFree(userCreditScore) {
  return request({
    url: '/api/rental/deposit-free',
    method: 'get',
    params: { userCreditScore }
  })
}

// 信用分相关接口
export function checkRentalEligibility(userId, houseId) {
  return request({
    url: '/api/rental/eligibility',
    method: 'get',
    params: { userId, houseId }
  })
}

export function getHousesByCreditScore(creditScore, params) {
  return request({
    url: '/api/rental/houses/credit-score',
    method: 'get',
    params: { creditScore, ...params }
  })
} 